import Login from "@/pages/Login/Login";
import Layout from "@/pages/Layout/Layout";
// import Download from "@/pages/Download/Download";
// import Dashboard from "@/pages/Dashboard/Dashboard";
import AuthRoute from "@/components/AuthRoute";
import { lazy, Suspense } from "react";

// lazy 函数
const Download = lazy(() => import("@/pages/Download/Download"));
const Dashboard = lazy(() => import("@/pages/Dashboard/Dashboard"));
// AuthRoute 就不用懒加载了，因为它每次都加载

const { createHashRouter } = require("react-router-dom");
const router = createHashRouter([
  {
    path: "/",
    element: (
      <AuthRoute>
        <Layout />
      </AuthRoute>
    ),
    children: [
      {
        path: "/dashboard",
        element: (
          <Suspense fallback={<div>Loading...</div>}>
            <Dashboard />
          </Suspense>
        ),
      },
      {
        path: "/download",
        element: (
          <Suspense fallback={<div>Loading...</div>}>
            <Download />
          </Suspense>
        ),
      },
    ],
  },
  { path: "/login", element: <Login /> },
]);

export default router;
